package LeetCode.month02.day54;

public class No713 {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int res = 0;
        int left = 0;
        int sum = 1;
        int n = nums.length;
        for (int right = 0; right <n; right++) {
            res+=right-left+1;
            sum*=nums[right];
            while(sum>=k&&left<n){
                sum/=nums[left++];
                res = Math.max(0,res-1);
            }
        }
        return res;
    }
}
